package com.tuanzi.loan.business.service.sms.impl;

import com.google.common.collect.Lists;
import com.google.gson.JsonObject;
import com.starbaba.model.utils.JSONUtils;
import com.tuanzi.loan.business.constants.DictionaryCode;
import com.tuanzi.loan.business.entity.sms.SmsSendTask;
import com.tuanzi.loan.business.entity.sms.SmsSendTaskStatus;
import com.tuanzi.loan.business.entity.sms.SmsTaskNumber;
import com.tuanzi.loan.business.entity.system.Dictionary;
import com.tuanzi.loan.business.repository.sms.SmsSendTaskRepository;
import com.tuanzi.loan.business.repository.sms.SmsTaskNumberRepository;
import com.tuanzi.loan.business.service.sms.SmsSendTaskService;
import com.tuanzi.loan.business.service.system.DictionaryService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.service.CommonServiceImpl;
import com.tuanzi.loan.core.util.ThrowableUtils;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.family.SmsSendTaskSearchRequest;
import com.tuanzi.loan.vo.response.family.SmsSendTaskSearchResponse;
import com.tuanzi.server.loan_base.constant.sms.SmsPlatformChannel;
import com.tuanzi.server.loan_base.model.response.sms.text.ShengShiXinAnMessageResponse;
import com.tuanzi.server.loan_base.util.sms.text.OuYiScreenMessage;
import com.tuanzi.server.loan_base.util.sms.text.SendBatchMessage;
import com.tuanzi.server.loan_base.util.sms.text.ZhengTongMultimediaMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.tuanzi.server.loan_base.constant.sms.SmsPlatformChannel.*;

/**
 * @author Ray 2017/09/21
 */
@Debug
@Slf4j
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class SmsSendTaskServiceImpl extends CommonServiceImpl<SmsSendTask, Long> implements SmsSendTaskService {

	private static String SUCCESS_STATUS = "Success";

	@Autowired
	private SmsSendTaskRepository smsSendTaskRepository;
	@Autowired
	private SmsTaskNumberRepository smsTaskNumberRepository;
	@Autowired
	private DictionaryService dictionaryService;
	@Autowired
	private StringRedisTemplate stringRedisTemplate;

	private final static String SMS_SEND_TASK_KEY = "sms-send-task:%s";

	@Override
	protected JpaRepository<SmsSendTask, Long> getRepository() {
		return smsSendTaskRepository;
	}

	@Override
	public SmsSendTask findTopOneByStatusAndExecuteTimeBefore(SmsSendTaskStatus status, Date executeDate) {
		return smsSendTaskRepository.findTopByStatusAndExecuteTimeBefore(status, executeDate);
	}

	@Override
	public SmsSendTask findTopOneByStatus(SmsSendTaskStatus status) {
		return smsSendTaskRepository.findTopByStatus(status);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRES_NEW)
	public void updateStatusWithoutTransactional(SmsSendTask smsSendTask, SmsSendTaskStatus status) {
		smsSendTask.setStatus(status);
		smsSendTaskRepository.save(smsSendTask);
	}

	@Override
	public List<SmsSendTask> findByStatus(SmsSendTaskStatus status) {
		return smsSendTaskRepository.findByStatusAndSendTimeIsNotNull(status);
	}

	@Override
	public Page<SmsSendTaskSearchResponse> list(PageSearcher<SmsSendTaskSearchRequest> pageSearcher) {
		return smsSendTaskRepository.list(pageSearcher.getSearchCondition(), pageSearcher.getPageable());
	}

	@Override
	public void cancelTask(Long smsSendTaskId) {
		SmsSendTask smsSendTask = smsSendTaskRepository.findOne(smsSendTaskId);
		smsSendTask.setStatus(SmsSendTaskStatus.SEND_CANCEL);
		smsSendTaskRepository.save(smsSendTask);
	}

	@Override
	public SmsSendTask resend(Long smsSendTaskId) {
		SmsSendTask smsSendTask = smsSendTaskRepository.findOne(smsSendTaskId);
		smsSendTask.setStatus(SmsSendTaskStatus.READY_SEND);
		stringRedisTemplate.delete(String.format(SMS_SEND_TASK_KEY, smsSendTaskId));
		return smsSendTaskRepository.save(smsSendTask);
	}

	@Override
	public Long countByStatus(SmsSendTaskStatus status) {
		return smsSendTaskRepository.countByStatus(status);
	}

	@Override
	public SmsSendTask addSmsSendTask(Long calculateTaskId) {

		SmsSendTask task = smsSendTaskRepository.findTopByCalculateTaskIdAndStatus(calculateTaskId, SmsSendTaskStatus.WAITING_SUBMIT);

		if (task != null) {
			return task;
		}

		task = new SmsSendTask();
		task.setStatus(SmsSendTaskStatus.WAITING_SUBMIT);
		task.setCalculateTaskId(calculateTaskId);
		task.setCreateTime(new Date());
		return smsSendTaskRepository.save(task);
	}

	@Override
	@Transactional(propagation= Propagation.NOT_SUPPORTED)
	public void sendSms(SmsSendTask smsSendTask) {
		try {
			List<String> mobNums = smsTaskNumberRepository.findAllByTaskId(smsSendTask.getCalculateTaskId()).stream().
					map(SmsTaskNumber::getMobnum).distinct().collect(Collectors.toList());
			mobNums = addAdminMobNums(mobNums);

			if (smsSendTask.getPlatformChannel() != null) {
				Dictionary dictionary = dictionaryService.findByCodeAndName(DictionaryCode.SMS_PLATFORM_PER_PRICE, smsSendTask.getPlatformChannel().toString());
				if (dictionary != null && StringUtils.isNotBlank(dictionary.getValue1()) && NumberUtils.isNumber(dictionary.getValue1())) {
					Double perPrice = NumberUtils.toDouble(dictionary.getValue1());
					smsSendTask.setCost(perPrice * mobNums.size());
				}
			}

			//分割单次提交数量（短信平台提交接口限制）
			List<String> smsTaskNumbers = Lists.newArrayList();
			if(smsSendTask.getPlatformChannel() == SmsPlatformChannel.JUCHEN.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.RONGTONGDA.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.JUCHEN_NEW.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.JUCHEN_TELCOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.JUCHEN_UNICOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.JU_CHEN_UNICOM_ONE_TO_ONE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.LING_DAO_YI_MOBILE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.LING_DAO_YI_UNICOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.LING_DAO_YI_WECHAT_ACCOUNT.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.LING_DAO_YI_TELCOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_JUCHEN_MOBILE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_JUCHEN_UNIOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_JUCHEN_TELCOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_LINGDAOTONG_MOBILE.getId()) {
				smsTaskNumbers = splitSmsTaskNumbers(mobNums, 5000);

			}else if(smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_YESI_MOBILE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_YESI_UNIOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_YESI_TELCOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_SANSANYI_MOBILE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_SANSANYI_UNIOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_SANSANYI_TELCOM.getId()){
				smsTaskNumbers = splitSmsTaskNumbers(mobNums, 4000);

			}else if(smsSendTask.getPlatformChannel() == SmsPlatformChannel.DINGHAN.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.DINGHAN_NEW_MESSAGE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.OUYI_SCREEN.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.QIAN_XU_MESSAGE.getId()){
				smsTaskNumbers = splitSmsTaskNumbers(mobNums, 2000);

			}else if(smsSendTask.getPlatformChannel() == SmsPlatformChannel.OUYI.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.OUYISHANXIN.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.OU_YI_UNICOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.DAHANGSANTONG.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.YUNFENG_WANGDAI.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.KUAIJIAYI.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.YUNFENG_WANGDAI_NEW.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.MENGWANG.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.ZHENG_TONG_MULTIMEDIA_MESSAGE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.YUN_FENG_ZHUAN_MA_MESSAGE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_YUNFENG_MOBILE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.BOLUODAI_YUNFENG_MOBILE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_OUYI_MOBILE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_OUYI_SHANXIN.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_OUYI_WENCAI_MOBILE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_YUNFENG.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_MENGWANG.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_WUXI_MOBILE.getId()){

				smsTaskNumbers = splitSmsTaskNumbers(mobNums, 1000);

			}else if(smsSendTask.getPlatformChannel() == SmsPlatformChannel.ZHENGTONG.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.ZHENGTONG_ADD_WHITE_LIST.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.ZHENGTONG_UNICOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.ZHENGTONG_TELECOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.SHENGSHIXINAN_UNICOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.SHENGSHIXINAN_MOBILE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.SHENGSHIXINAN_TELCOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.LINGWAN_MOBILE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.FUYAO.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.SHENGSHIXINAN_FLASH.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONG_HUA_HUA_SHEGNSHIXINAN_MOBILE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONG_HUA_HUA_SHENGSHIXINAN_UNICOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONG_HUA_HUA_SHENGSHIXINAN_TELCOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.BOLUODAI_BINGJI_UNIOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_BINGJI_UNIOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_YIDAO_MOBILE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_YIDAO_TELCOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_SHENGSHIXINAN_SHANXIN_MOBILE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_SHENGSHIXINAN_SHANXIN_UNIOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_BINGJI_MOBILE.getId()){

				smsTaskNumbers = splitSmsTaskNumbers(mobNums, 10000);

			}else if(smsSendTask.getPlatformChannel() == SmsPlatformChannel.RIRISHENG.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.JIU_LING_MESSAGE.getId()){
				smsTaskNumbers = splitSmsTaskNumbers(mobNums, 15000);

			}else if(smsSendTask.getPlatformChannel() == SmsPlatformChannel.BOBO_TELECOM.getId()){
				smsTaskNumbers = splitSmsTaskNumbers(mobNums, 20000);

			} else if(smsSendTask.getPlatformChannel() == SmsPlatformChannel.BOBO.getId()){
				smsTaskNumbers = splitSmsTaskNumbers(mobNums, 50000);

			}else if(smsSendTask.getPlatformChannel() == SmsPlatformChannel.SHENGSHIXINAN.getId() || smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_DEYI.getId()
				|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.BLD_TENGXIN_CMCC.getId()
				|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.BLD_TENGXIN_UNICOM.getId()
				|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_TENGXIN_CMCC.getId()
				|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_TENGXIN_UNICOM.getId()){
				smsTaskNumbers = splitSmsTaskNumbers(mobNums, 500);

			}else if(smsSendTask.getPlatformChannel() == SmsPlatformChannel.YE_SI_NEW_MESSAGE.getId()){
				smsTaskNumbers = splitSmsTaskNumbers(mobNums, 100);
			}else if (smsSendTask.getPlatformChannel() == SmsPlatformChannel.BOLUODAI_XIAOXIYUN_MOBILE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.BOLUODAI_XIAOXIYUN_UNIOM.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_XIAOXIYUN_MOBILE.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_XIAOXIYUN_MOBILE_106.getId()
					|| smsSendTask.getPlatformChannel() == SmsPlatformChannel.XIONGHUAHUA_XIAOXIYUN_UNIOM.getId()) {
				smsTaskNumbers = splitSmsTaskNumbers(mobNums, 200);
			} else {
				smsTaskNumbers = splitSmsTaskNumbers(mobNums, 100000);

			}

			List<String> taskIds = Lists.newArrayList();

			smsTaskNumbers.stream().forEach(x -> {
				try {
					// 调用发送接口
					String result = "";
					if(smsSendTask.getPlatformChannel() == SmsPlatformChannel.OUYI_SCREEN.getId()){
						result = OuYiScreenMessage.send(x, smsSendTask.getTemplateId());
					}else if(smsSendTask.getPlatformChannel() == SmsPlatformChannel.ZHENG_TONG_MULTIMEDIA_MESSAGE.getId()){ //一道正通彩信

						result = ZhengTongMultimediaMessage.send(x, smsSendTask.getContent(), smsSendTask.getId(), smsSendTask.getMmsPicUrl());

					}else{
						result = SendBatchMessage.send(x, smsSendTask.getContent(), smsSendTask.getPlatformChannel(), smsSendTask.getId());
					}

					//记录响应参数(除了响应参数过大的通道)
					if(!Lists.newArrayList(SHENGSHIXINAN.getId(), YUN_ZHI_SHU.getId(), YE_SI_NEW_MESSAGE.getId(),
							XIONGHUAHUA_FENZHI_UNIOM.getId(), BOLUODAI_FENZHI_UNIOM.getId(),XIONGHUAHUA_FENZHI_FEIYU_UNIOM.getId()).contains(smsSendTask.getPlatformChannel())){
						smsSendTask.setResult((StringUtils.isBlank(smsSendTask.getResult()) ? StringUtils.EMPTY : smsSendTask.getResult()) + result);
					}

					// 构造短信平台返回对象
					SmsPlatformResult resultObj = structureSmsPlatformResult(result, smsSendTask.getPlatformChannel());

					if (resultObj == null) {
						smsSendTask.setStatus(SmsSendTaskStatus.SEND_FAIL);
						smsSendTask.setErrorReason("短信平台接口没返回任何信息,请与短信平台联系");
					} else {
						if (resultObj.isSuccess()) {
							taskIds.add(resultObj.getTaskId() + StringUtils.EMPTY);
							smsSendTask.setStatus(SmsSendTaskStatus.SEND_DONE);
						} else {
							smsSendTask.setStatus(SmsSendTaskStatus.SEND_FAIL);
							smsSendTask.setErrorReason(
									(StringUtils.isBlank(smsSendTask.getErrorReason()) ? StringUtils.EMPTY : smsSendTask.getErrorReason()) + resultObj.getMessage());
						}
					}

				} catch (Exception e) {
					log.error(e.getMessage(), e);
				}
			});
			smsSendTask.setTaskId(taskIds.stream().collect(Collectors.joining(",")));
		} catch (Throwable e) {
			log.error(e.getMessage(), e);
			smsSendTask.setErrorReason(ThrowableUtils.getStackTraceString(e));
			smsSendTask.setStatus(SmsSendTaskStatus.SEND_FAIL);
		} finally {
			String finalResult = smsSendTask.getResult();
			// 避免保存结果时超出字段长度
			if (StringUtils.isNotEmpty(finalResult)) {
				smsSendTask.setResult(finalResult.substring(0, Math.min(finalResult.length(), 16384))); // 最多保存16k个字符
			}
			smsSendTaskRepository.save(smsSendTask);
		}
	}

	/**
	 *
	 * @param smsTaskNumbers 手机号集合
	 * @param eachListMaxCount 每次分割的条数
	 * @return
	 */
	private List<String /* phone numbers */> splitSmsTaskNumbers(List<String> smsTaskNumbers, Integer eachListMaxCount) {
		List<String> splitedSmsTaskNumbers = Lists.newArrayList();

		if (CollectionUtils.isEmpty(smsTaskNumbers)) {
			return splitedSmsTaskNumbers;
		}

		Float total = smsTaskNumbers.size() + 0.0F;

		if (total <= eachListMaxCount) {
			splitedSmsTaskNumbers.add(structurePhoneNumbers(smsTaskNumbers));
			return splitedSmsTaskNumbers;
		}

		Integer foreachCount = (int) Math.ceil(total / eachListMaxCount);
		for (int i = 0; i < foreachCount; i++) {
			Integer startIndex = i * eachListMaxCount;
			Integer tmpEndIndex = (i + 1) * eachListMaxCount;
			Integer endIndex = tmpEndIndex > smsTaskNumbers.size() ? smsTaskNumbers.size() : tmpEndIndex;
			List<String> eachSmsTaskNumbers = smsTaskNumbers.subList(startIndex, endIndex);
			splitedSmsTaskNumbers.add(structurePhoneNumbers(eachSmsTaskNumbers));
		}

		return splitedSmsTaskNumbers;
	}

	private String structurePhoneNumbers(List<String> phoneNumbers) {
		return phoneNumbers.parallelStream().collect(Collectors.joining(","));
	}

	private List<String> addAdminMobNums(List<String> mobNums) {
		mobNums.add("18529166107");
		mobNums.add("13416103001");
		mobNums.add("18588662097");
		mobNums.add("18819475730");
		mobNums.add("13725229683");
		mobNums.add("18813973736");
		mobNums.add("17876251937");
		mobNums.add("13288599591");
		mobNums.add("18344160500");
		return mobNums;
	}

	/**
	 * 构造短信平台返回结果
	 * @param resultStr 结果
	 * @param smsPlatformChannel 短信平台
	 * @return
	 */
	private SmsSendTaskService.SmsPlatformResult structureSmsPlatformResult(String resultStr, Integer smsPlatformChannel) {
		if (StringUtils.isBlank(resultStr)) {
			return null;
		}

		try {
			SmsSendTaskService.SmsPlatformResult result = new SmsSendTaskService.SmsPlatformResult();
			if(smsPlatformChannel == SmsPlatformChannel.JUCHEN.getId()
					|| smsPlatformChannel == SmsPlatformChannel.JUCHEN_NEW.getId()
					|| smsPlatformChannel == SmsPlatformChannel.BOBO.getId()
					|| smsPlatformChannel == SmsPlatformChannel.JUCHEN_TELCOM.getId()
					|| smsPlatformChannel == SmsPlatformChannel.JUCHEN_UNICOM.getId()
					|| smsPlatformChannel == SmsPlatformChannel.JU_CHEN_UNICOM_ONE_TO_ONE.getId()) { //巨辰、波波平台

				result = structJuChenOrBoBoResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.WUXI.getId()) { //五玺平台

				result = structWuXiResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.DINGHAN.getId()
					|| smsPlatformChannel == SmsPlatformChannel.DINGHAN_NEW_MESSAGE.getId()){ //鼎汉平台

				result = structDingHanResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.OUYI.getId()
					|| smsPlatformChannel == SmsPlatformChannel.OUYISHANXIN.getId()
					|| smsPlatformChannel == SmsPlatformChannel.OU_YI_UNICOM.getId()
					|| smsPlatformChannel == SmsPlatformChannel.XIONGHUAHUA_OUYI_MOBILE.getId()
					|| smsPlatformChannel == SmsPlatformChannel.XIONGHUAHUA_OUYI_SHANXIN.getId()
					|| smsPlatformChannel == SmsPlatformChannel.XIONGHUAHUA_OUYI_WENCAI_MOBILE.getId()) { //欧一

				result = structOuYiResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.DAHANGSANTONG.getId()) {  //大汉三通平台

				result = structDaHanSanTongResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.YUNFENG_WANGDAI.getId()
					|| smsPlatformChannel == SmsPlatformChannel.YUNFENG_WANGDAI_NEW.getId()
					|| smsPlatformChannel == SmsPlatformChannel.YUN_FENG_ZHUAN_MA_MESSAGE.getId()
					|| smsPlatformChannel == SmsPlatformChannel.XIONGHUAHUA_YUNFENG.getId()) { //云锋平台

				result = structYunFengResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.ZHENGTONG.getId()
					|| smsPlatformChannel == SmsPlatformChannel.RONGTONGDA.getId()
					|| smsPlatformChannel == SmsPlatformChannel.RIRISHENG.getId()
					|| smsPlatformChannel == SmsPlatformChannel.ZHENGTONG_ADD_WHITE_LIST.getId()
					|| smsPlatformChannel == SmsPlatformChannel.ZHENGTONG_UNICOM.getId()
					|| smsPlatformChannel == SmsPlatformChannel.ZHENGTONG_TELECOM.getId()
					|| smsPlatformChannel == SmsPlatformChannel.JIU_LING_MESSAGE.getId()){  //正通、蓉通达、日日晟平台、玖零信息

				result = structZhengTongOrRongOrRiRiShengTongDaResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.KUAIJIAYI.getId()){ //快加易
				result = structKuaiJiaYiMessageResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.SHENGSHIXINAN.getId()){  //盛世新安

				result = structShengShiXinAnResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.SHENGSHIXINAN_MOBILE.getId()
					|| smsPlatformChannel == SmsPlatformChannel.SHENGSHIXINAN_UNICOM.getId()
					|| smsPlatformChannel == SmsPlatformChannel.SHENGSHIXINAN_TELCOM.getId()
					|| smsPlatformChannel == SmsPlatformChannel.SHENGSHIXINAN_FLASH.getId()
					|| smsPlatformChannel == SmsPlatformChannel.XIONG_HUA_HUA_SHEGNSHIXINAN_MOBILE.getId()
					|| smsPlatformChannel == SmsPlatformChannel.XIONG_HUA_HUA_SHENGSHIXINAN_UNICOM.getId()
					|| smsPlatformChannel == SmsPlatformChannel.XIONG_HUA_HUA_SHENGSHIXINAN_TELCOM.getId()
					|| smsPlatformChannel == SmsPlatformChannel.XIONGHUAHUA_SHENGSHIXINAN_SHANXIN_MOBILE.getId()
					|| smsPlatformChannel == SmsPlatformChannel.XIONGHUAHUA_SHENGSHIXINAN_SHANXIN_UNIOM.getId()){ //盛世新安（新账号）

				result = structShengShiXinAnResultNew(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.OUYI_SCREEN.getId()){ // 欧一屏信

				result = structOuYiScreenResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.LINGWAN_MOBILE.getId()){ //领网

				result = structLingWangResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.MENGWANG.getId() || smsPlatformChannel == SmsPlatformChannel.XIONGHUAHUA_MENGWANG.getId()){  //梦网

				result = structMengWangResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.FUYAO.getId()){ //埠垚

				result = structFuYaoResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.YUN_ZHI_SHU.getId()){ //云之树

				result = structYunZhiShuResult(resultStr);

			} else if(smsPlatformChannel == SmsPlatformChannel.ZHENG_TONG_MULTIMEDIA_MESSAGE.getId()){ //一道正通彩信

				result = structZhengTongMMsResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.LING_DAO_YI_MOBILE.getId()
					|| smsPlatformChannel == SmsPlatformChannel.LING_DAO_YI_UNICOM.getId()
					|| smsPlatformChannel == SmsPlatformChannel.LING_DAO_YI_WECHAT_ACCOUNT.getId()
					|| smsPlatformChannel == SmsPlatformChannel.LING_DAO_YI_TELCOM.getId()
					|| smsPlatformChannel == SmsPlatformChannel.XIONGHUAHUA_LINGDAOTONG_MOBILE.getId()){  //领道易

				result = structLingDaoYiResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.QIAN_XU_MESSAGE.getId()){

				result = structQianXuResult(resultStr);

			} else if(smsPlatformChannel.equals(SmsPlatformChannel.YE_SI_NEW_MESSAGE.getId())){

				result = structYesiNewResult(resultStr);

			} else if(smsPlatformChannel.equals(BOLUODAI_HAOBO_MOBILE.getId()) || smsPlatformChannel.equals(BOLUODAI_HAOBO_UNIOM.getId()) || smsPlatformChannel.equals(BOLUODAI_HAOBO_TELCOM.getId())
				|| smsPlatformChannel == XIONGHUAHUA_HAOBO_MOBILE.getId() || smsPlatformChannel == XIONGHUAHUA_HAOBO_UNIOM.getId() ||smsPlatformChannel == XIONGHUAHUA_HAOBO_TELCOM.getId()){

				result = strucBoLuoDaiHaoBoResult(resultStr);

			}else if (smsPlatformChannel == XIONGHUAHUA_FENZHI_UNIOM.getId() || smsPlatformChannel == BOLUODAI_FENZHI_UNIOM.getId()) {
				result = structFenZhiFeiYuResult(resultStr);
			} else if (smsPlatformChannel == SmsPlatformChannel.XIONGHUAHUA_YUNFENG_MOBILE.getId() || smsPlatformChannel == SmsPlatformChannel.BOLUODAI_YUNFENG_MOBILE.getId()) {
				result = strucYunFengResult(resultStr);
			}else if (smsPlatformChannel == SmsPlatformChannel.BOLUODAI_XIAOXIYUN_MOBILE.getId() || smsPlatformChannel == SmsPlatformChannel.BOLUODAI_XIAOXIYUN_UNIOM.getId()
					|| smsPlatformChannel == SmsPlatformChannel.XIONGHUAHUA_XIAOXIYUN_MOBILE.getId()
					|| smsPlatformChannel == SmsPlatformChannel.XIONGHUAHUA_XIAOXIYUN_MOBILE_106.getId()
					|| smsPlatformChannel == SmsPlatformChannel.XIONGHUAHUA_XIAOXIYUN_UNIOM.getId()) {
				result = structXiaoXiYunResult(resultStr);
			} else if(smsPlatformChannel.equals(SmsPlatformChannel.XIONGHUAHUA_FENZHI_UNIOM.getId())
					|| smsPlatformChannel.equals(SmsPlatformChannel.BOLUODAI_FENZHI_UNIOM.getId())
					|| smsPlatformChannel == SmsPlatformChannel.XIONGHUAHUA_FENZHI_FEIYU_UNIOM.getId()){ //分治

				result = structFenZhiResult(resultStr);

			}else if(smsPlatformChannel == SmsPlatformChannel.BLD_TENGXIN_CMCC.getId()
					|| smsPlatformChannel == SmsPlatformChannel.BLD_TENGXIN_UNICOM.getId()
					|| smsPlatformChannel == SmsPlatformChannel.XIONGHUAHUA_TENGXIN_CMCC.getId()
					|| smsPlatformChannel == SmsPlatformChannel.XIONGHUAHUA_TENGXIN_UNICOM.getId()){
				result = structTengXinResult(resultStr);
			}
			else {  //其他平台

				List<Element> elements = DocumentHelper.parseText(resultStr).getRootElement().elements();

				for (Element element : elements) {
					switch (element.getName()) {
						case "returnstatus":
							result.setStatus(element.getStringValue());
							break;
						case "message":
							result.setMessage(element.getStringValue());
							break;
						case "remainpoint":
							result.setRemainPoint(NumberUtils.toLong(element.getStringValue()));
							break;
						case "taskID":
							result.setTaskId(element.getStringValue());
							break;
						case "successCounts":
							result.setSuccessCounts(NumberUtils.toLong(element.getStringValue()));
							break;
					}
				}
			}
			return result;
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		}
		return null;
	}
    /**
     * 小溪云
     * @param resultStr 响应
     */
    private SmsPlatformResult structXiaoXiYunResult(String resultStr) {
        SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
        if ("0".equals(resultStr)) { // 提交批次是否成功
            smsPlatformResult.setStatus(SUCCESS_STATUS);
        } else {
            smsPlatformResult.setMessage(resultStr); // 错误码
//			0 成功
//			1 失败
//			2 参数校验失败
//			3 余额不足
//			4 用户不存在
//			5 产品不存在
//			6 sign 校验失败
//			7 IP 校验失败
//			8 time 时间格式错误
//			9 扩展号格式错误
//			11 短信内容过长
//			14 ts 校验有误，要求 5 分钟内有效
//			15 号码个数超过限制
        }
        return smsPlatformResult;
    }
	/**
	 * 分治
	 * @param resultStr 响应
	 */
	private SmsPlatformResult structFenZhiFeiYuResult(String resultStr) {
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		JsonObject jsonObject = JSONUtils.toJsonObject(resultStr);
		String subStat = JSONUtils.checkAsString(jsonObject, "subStat");
		if("r:000".equals(subStat)){
			smsPlatformResult.setStatus(SUCCESS_STATUS);
		}else {
			smsPlatformResult.setMessage(JSONUtils.checkAsString(jsonObject,"subStatDes"));
		}
		return smsPlatformResult;
	}
	/**
	 * 云峰
	 * @param resultStr 响应
	 */
	private SmsPlatformResult strucYunFengResult(String resultStr) {
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		JsonObject jsonObject = JSONUtils.toJsonObject(resultStr);
		String result = JSONUtils.checkAsString(jsonObject, "errorCode");
		if("000000".equals(result)){
			smsPlatformResult.setStatus(SUCCESS_STATUS);
		}else {
			smsPlatformResult.setMessage(JSONUtils.checkAsString(jsonObject,"errorMsg"));
		}
		return smsPlatformResult;
	}
	/**
	 * 菠萝贷-昊博
	 * @param resultStr 响应
	 */
	private SmsPlatformResult strucBoLuoDaiHaoBoResult(String resultStr) {
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		JsonObject jsonObject = JSONUtils.toJsonObject(resultStr);
		Boolean result = JSONUtils.checkAsBoolean(jsonObject, "success");
		if(result){
			smsPlatformResult.setStatus(SUCCESS_STATUS);
		}else {
			smsPlatformResult.setMessage(JSONUtils.checkAsString(jsonObject,"r"));
		}
		return smsPlatformResult;
	}
	/**
	 * 千煦
	 * @param resultStr 响应
	 */
	private SmsPlatformResult structQianXuResult(String resultStr) {
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		//{"code":200,"message":"SUCCESS","order_id":"2019041211881000001931305927"}
		JsonObject jsonObject = JSONUtils.toJsonObject(resultStr);
		int code = JSONUtils.checkAsInt(jsonObject, "code");
		if(200 == code){
			smsPlatformResult.setStatus(SUCCESS_STATUS);
		}else{
			String desc = JSONUtils.checkAsString(jsonObject, "message");
			smsPlatformResult.setMessage(desc);
		}

		return smsPlatformResult;
	}

	/**
	 * 构造巨辰、波波平台响应结果
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structJuChenOrBoBoResult(String response){
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		JsonObject jsonObject = JSONUtils.toJsonObject(response);
		String batchno = JSONUtils.checkAsString(jsonObject, "batchno");
		String respcode = JSONUtils.checkAsString(jsonObject, "respcode");
		String respdesc = JSONUtils.checkAsString(jsonObject, "respdesc");
		if("0".equals(respcode)) {
			smsPlatformResult.setStatus(SUCCESS_STATUS);
			smsPlatformResult.setTaskId(batchno);
		}else {
			smsPlatformResult.setMessage(respdesc);
		}
		return smsPlatformResult;
	}

	/**
	 * 构造五玺平台响应结果
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structWuXiResult(String response){
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		JsonObject jsonObject = JSONUtils.toJsonObject(response);
		Integer status = JSONUtils.checkAsInt(jsonObject, "status");
		String message = JSONUtils.checkAsString(jsonObject, "message");
		String taskId = JSONUtils.checkAsString(jsonObject, "taskId");
		if(status == 0) {
			smsPlatformResult.setStatus(SUCCESS_STATUS);
			smsPlatformResult.setTaskId(taskId);
		}else {
			smsPlatformResult.setMessage(message);
		}
		return smsPlatformResult;
	}

	/**
	 * 构造鼎汉平台响应结果
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structDingHanResult(String response){
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		String[] responseArray = StringUtils.split(response, ",");
		String status = responseArray[0];
		if("1".equals(status)) {
			String taskId = responseArray[1];
			smsPlatformResult.setStatus(SUCCESS_STATUS);
			smsPlatformResult.setTaskId(taskId);
		}else {
			smsPlatformResult.setMessage(status);
		}
		return smsPlatformResult;

	}

	/**
	 * 构造欧一、欧一闪信平台响应结果
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structOuYiResult(String response){
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		JsonObject jsonObject = JSONUtils.toJsonObject(response);
		boolean success = JSONUtils.checkAsBoolean(jsonObject, "success");
		if(success) {
			String id = JSONUtils.checkAsString(jsonObject, "id");//短信任务ID
			smsPlatformResult.setStatus(SUCCESS_STATUS);
			smsPlatformResult.setTaskId(id);
		}else {
			String r = JSONUtils.checkAsString(jsonObject, "r"); //错误码
			smsPlatformResult.setMessage(r);
		}
		return smsPlatformResult;
	}


	/**
	 * 构造大汉三通平台响应结果
	 * @param response
	 * @return
	 */
	private SmsSendTaskService.SmsPlatformResult structDaHanSanTongResult(String response){
		SmsSendTaskService.SmsPlatformResult smsPlatformResult = new SmsSendTaskService.SmsPlatformResult();
		JsonObject responseJson = JSONUtils.toJsonObject(response);
		String result = JSONUtils.checkAsString(responseJson, "result");
		if(StringUtils.equals("0", result)) {
			String msgid = JSONUtils.checkAsString(responseJson, "msgid");
			smsPlatformResult.setStatus(SUCCESS_STATUS);
			smsPlatformResult.setTaskId(msgid);
		}else {
			String desc = JSONUtils.checkAsString(responseJson, "desc");
			smsPlatformResult.setMessage(desc);
		}

		return smsPlatformResult;
	}


	/**
	 * 构造云锋平台响应结果
	 * @param response
	 * @return
	 */
	private SmsSendTaskService.SmsPlatformResult structYunFengResult(String response){
		SmsSendTaskService.SmsPlatformResult smsPlatformResult = new SmsSendTaskService.SmsPlatformResult();
		JsonObject responseJson = JSONUtils.toJsonObject(response);
		String errorCode = JSONUtils.checkAsString(responseJson, "errorCode");
		if(StringUtils.equals("000000", errorCode)) {
			smsPlatformResult.setStatus(SUCCESS_STATUS);
		}else {
			String errorMsg = JSONUtils.checkAsString(responseJson, "errorMsg");
			smsPlatformResult.setMessage(errorMsg);
		}

		return smsPlatformResult;
	}

	/**
	 * 构造正通、蓉通达、日日晟平台响应结果
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structZhengTongOrRongOrRiRiShengTongDaResult(String response){
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		if(NumberUtils.isNumber(response) && response.compareTo("0") > 0){
			smsPlatformResult.setStatus(SUCCESS_STATUS);
			smsPlatformResult.setTaskId(response);
		}else{
			smsPlatformResult.setMessage(response);
		}
		return smsPlatformResult;
	}


	/**
	 * 构造快加易返回结果
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structKuaiJiaYiMessageResult(String response) throws DocumentException {
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		List<Element> elements = DocumentHelper.parseText(response).getRootElement().elements();
		String status = null;
		String seq = null;
		String error = null;

		for (Element element : elements) {
			if("status".equals(element.getName())){
				status = element.getStringValue();
			}

			if("seq".equals(element.getName())){
				seq = element.getStringValue();
			}

			if("error".equals(element.getName())){
				error =element.getStringValue();
			}
		}

		if(StringUtils.isBlank(status)){
			smsPlatformResult.setMessage("对方没有返回发送状态");
		}else{
			if("1".equals(status)){
				smsPlatformResult.setTaskId(seq);
				smsPlatformResult.setStatus(SUCCESS_STATUS);
			}else{
				smsPlatformResult.setMessage(error);
			}
		}

		return smsPlatformResult;
	}

	/**
	 * 构造盛世新安短信响应结果
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structShengShiXinAnResult(String response){
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		JsonObject responseJson = JSONUtils.toJsonObject(response);
		Integer c = JSONUtils.checkAsInt(responseJson, "c");
		if(c == 200){
			smsPlatformResult.setStatus(SUCCESS_STATUS);
		}else{
			String e = JSONUtils.checkAsString(responseJson, "e");
			smsPlatformResult.setMessage(e);
		}
		return smsPlatformResult;
	}


	/**
	 * 构造盛世新安短信响应结果（新）
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structShengShiXinAnResultNew(String response){

		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		if(JSONUtils.isGoodJson(response)){
			ShengShiXinAnMessageResponse shengShiXinAnMessageResponse = JSONUtils.fromJsonNew(response, ShengShiXinAnMessageResponse.class);
			if(shengShiXinAnMessageResponse != null && shengShiXinAnMessageResponse.getCode() != null
					&& shengShiXinAnMessageResponse.getCode().equals(0)){
				smsPlatformResult.setStatus(SUCCESS_STATUS);
				if(shengShiXinAnMessageResponse.getTask_id() != null){
					smsPlatformResult.setTaskId(shengShiXinAnMessageResponse.getTask_id().toString());
				}
			}else{
				smsPlatformResult.setMessage(shengShiXinAnMessageResponse.getMessage());
			}
		}
		return smsPlatformResult;

	}

	/**
	 * 构造欧一屏信响应结果
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structOuYiScreenResult(String response){
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		JsonObject responseJson = JSONUtils.toJsonObject(response);
		String code = responseJson.get("code").getAsString();
		if(code.equals("00000000")){
			smsPlatformResult.setStatus(SUCCESS_STATUS);
		}else{
			String description = responseJson.get("description").getAsString();
			smsPlatformResult.setMessage(description);
		}
		return smsPlatformResult;
	}

	/**
	 * 构造领网短信响应结果
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structLingWangResult(String response){
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		JsonObject responseJson = JSONUtils.toJsonObject(response);
		String code = responseJson.get("code").getAsString();
		if(code.equals("0")){

			JsonObject dataJson = responseJson.get("data").getAsJsonObject();
			String taskCode = dataJson.get("taskcode").getAsString();

			smsPlatformResult.setStatus(SUCCESS_STATUS);
			smsPlatformResult.setTaskId(taskCode);
		}else{

			String message = responseJson.get("message").getAsString();
			smsPlatformResult.setMessage(message);
		}

		return smsPlatformResult;
	}


	/**
	 * 构造梦网短信响应结果
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structMengWangResult(String response){
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		JsonObject responseJson = JSONUtils.toJsonObject(response);
		String result = responseJson.get("result").getAsString();
		if("0".equals(result)){
			String taskId = responseJson.get("msgid").getAsString();
			smsPlatformResult.setStatus(SUCCESS_STATUS);
			smsPlatformResult.setTaskId(taskId);
		}else{
			smsPlatformResult.setMessage(result);
		}
		return smsPlatformResult;
	}

	/**
	 * 构造埠垚短信响应结果
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structFuYaoResult(String response){
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		String[] responseArray = response.split(",");
		String code = responseArray[0];
		String taskId = responseArray[1];
		if("0".equals(code)){
			smsPlatformResult.setStatus(SUCCESS_STATUS);
			smsPlatformResult.setTaskId(taskId);
		}else{
			smsPlatformResult.setMessage(code);
		}
		return smsPlatformResult;
	}


	/**
	 * 构造云之树短信响应结果
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structYunZhiShuResult(String response){
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		JsonObject responseJson = JSONUtils.toJsonObject(response);
		String code = responseJson.get("Status").getAsString();
		if("0".equals(code)){
			smsPlatformResult.setStatus(SUCCESS_STATUS);
		}else{
			smsPlatformResult.setMessage(code);
		}

		return smsPlatformResult;
	}


	/**
	 * 构造一道正通彩信响应结果
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structZhengTongMMsResult(String response){
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		if(NumberUtils.isNumber(response) && NumberUtils.toLong(response) > 0){
			smsPlatformResult.setStatus(SUCCESS_STATUS);
			smsPlatformResult.setTaskId(response);
		}else{
			smsPlatformResult.setMessage(response);
		}

		return smsPlatformResult;
	}

	/**
	 *
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structLingDaoYiResult(String response){
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		if("0".equals(response)){
			smsPlatformResult.setStatus(SUCCESS_STATUS);
		}else{
			smsPlatformResult.setMessage(response);
		}

		return smsPlatformResult;

	}

	/**
	 * 构造野思新账号响应结果
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structYesiNewResult(String response){

		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();

		JsonObject responseJson = JSONUtils.toJsonObject(response);
		Integer totalFee = JSONUtils.checkAsInt(responseJson, "total_fee");
		if(totalFee != null && totalFee > 0){
			smsPlatformResult.setStatus(SUCCESS_STATUS);
		}

		return smsPlatformResult;
	}

	/**
	 * 构造分支短信响应结果
	 * @param response
	 * @return
	 */
	private SmsPlatformResult structFenZhiResult(String response){
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();

		JsonObject responseJson = JSONUtils.toJsonObject(response);
		String subStat = JSONUtils.checkAsString(responseJson, "subStat");
		if("r:000".equals(subStat)){
			smsPlatformResult.setStatus(SUCCESS_STATUS);
		}
		return smsPlatformResult;
	}

	/**
	 * 构造腾信响应结果
	 * @param result
	 * @return
	 */
	private SmsPlatformResult structTengXinResult(String result){
		SmsPlatformResult smsPlatformResult = new SmsPlatformResult();
		if(StringUtils.isNotBlank(result)){
			if(result.contains("result=0")){
				smsPlatformResult.setStatus(SUCCESS_STATUS);
			}
		}
		return smsPlatformResult;
	}

	@Override
	public Map<String, String> findDistinctFirstNames() {
		List<String> firstPartyNames =  smsSendTaskRepository.findDistinctFirstPartyNames();
		Map<String, String> firstPartyNameMap = new HashMap<String, String>();
		for(String firstPartyName: firstPartyNames) {
			firstPartyNameMap.put(firstPartyName, firstPartyName);
		}
		return firstPartyNameMap;
	}
}
